#include <stdio.h>      /* printf, scanf, NULL */
#include <stdlib.h>     /* malloc, free, rand */
void generate(int i);
int main ()
{
  int i;
  printf ("How long do you want the string? ");
  scanf ("%d", &i);
  generate(i);
  return 0;
}

void generate(int a)
{
char * buffer;
buffer = (char*) malloc (a+1);
  if (buffer==NULL) exit (1);
  for (int b=0; b<a; b++)
    buffer[b]=rand()%26+'a';
  buffer[a]='\0';

  printf ("Random string: %s\n",buffer);
  free (buffer);
}
